package main

import (
	"fmt"
	"log"
"github.com/goquery"
	"os"
	"net/http"
	"io"
	"./spider"

	"Spider/channel"
)

func GetJokes(){
	doc, err := goquery.NewDocument("http://www.qiushibaike.com/text/")
	if err != nil{
		log.Fatal(err)
	}
	doc.Find("#content").Each(func(i int, s *goquery.Selection){
		//fmt.Println(s.Text())
		value:=s.Find(".content")
		index:=value.Find("span").Text()
		fmt.Println(index)
	})
}

func main(){
	//qiu:=new(spider.JokeSpider)
	//getpicture()
	qiu:=new(spider.PicSpider)
	go qiu.MakeUrls()
	go qiu.Query()
	go qiu.Download()
	<-channel.Sync2
	<-channel.Sync2
}

func getpicture(){
	file,err:=os.Create("hello.jpg")
	if err!=nil{
		log.Fatal(err)
		return
	}
	resp,err:=http.Get("http://pic.qiushibaike.com/system/pictures/12004/120044886/medium/app120044886.jpg")
	io.Copy(file,resp.Body)
}